package cn.sdormitory.controller;

import cn.sdormitory.common.api.CommonPage;
import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.violative.entity.ViolationClassInterval;
import cn.sdormitory.violative.form.ViolationClassIntervalQueryForm;
import cn.sdormitory.violative.form.ViolationClassIntervalReceiveForm;
import cn.sdormitory.violative.form.ViolationClassIntervalSaveForm;
import cn.sdormitory.violative.service.ViolationClassIntervalService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.jsonwebtoken.lang.Assert;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/app/violation/class/interval")
@Api("APP端违纪巡检管理接口")
public class AppViolationClassIntervalController {

    @Autowired
    private ViolationClassIntervalService violationClassIntervalService;

    /**
     * 查询违纪巡查信息
     * @param queryForm 查询参数
     * @return 查询结果
     */
    @PostMapping("/pageList")
    public CommonResult<CommonPage<ViolationClassInterval>> pageList(@RequestBody ViolationClassIntervalQueryForm queryForm){
        IPage<ViolationClassInterval> page = violationClassIntervalService.pageList(queryForm);
        return CommonResult.success(CommonPage.restPage(page));
    }

    /**
     * 获取违纪巡查详情
     * @param id 违纪id
     * @return 违纪信息
     */
    @GetMapping("/getDetail/{id}")
    public CommonResult<ViolationClassInterval> getDetail(@PathVariable long id){
        ViolationClassInterval detail = violationClassIntervalService.getDetail(id);
        Assert.notNull(detail,"获取详情失败");
        return CommonResult.success(detail);
    }

    @PostMapping("/save")
    public CommonResult<Boolean> saveViolationClassInterval(@RequestBody ViolationClassIntervalSaveForm saveForm){
        violationClassIntervalService.save(saveForm);
        return CommonResult.success(true);
    }


    @DeleteMapping("/{id}")
    public CommonResult<Boolean> deleteViolationClassInterval(@PathVariable long id){
        violationClassIntervalService.removeById(id);
        return CommonResult.success(true);
    }

    @PostMapping("/students/receive")
    public CommonResult<Boolean> receiveStudents(@RequestBody ViolationClassIntervalReceiveForm form){
        violationClassIntervalService.receiveStudents(form);
        return CommonResult.success(true);
    }

}
